package com.example.easyexcel.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.example.easyexcel.enums.UserStatusEnum;

/**
 * @author dangwen1
 * @date 2021年12月02日 20:38
 * @description
 */
public class UserStatusEnumConverter implements Converter<UserStatusEnum> {
    @Override
    public Class<UserStatusEnum> supportJavaTypeKey() {
        return UserStatusEnum.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public UserStatusEnum convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return UserStatusEnum.getByDesc(cellData.getStringValue());
    }

    @Override
    public CellData<UserStatusEnum> convertToExcelData(UserStatusEnum userStatusEnum, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new CellData<>(userStatusEnum.getDesc());
    }
}
